package or.exa.cangguan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.common.Page;
import or.exa.cangguan.common.Result;
import or.exa.cangguan.entity.vo.ShelfVo;
import or.exa.cangguan.service.ShelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "货架管理")
@RestController
public class ShelfController {


    @Autowired
    private ShelfService shelfService;

    //新增货架
    @ApiOperation(value = "新增货架")
    @PostMapping("shelf/add")
    public Result addShelf(@RequestBody ShelfVo shelfVo){
        int i = shelfService.addShelf(shelfVo);


        return i>0?Result.ok("新增成功"):Result.ok("新增失败");
    }


    //修改货架
    @ApiOperation(value = "修改货架")
    @PostMapping("shelf/update")
    public Result updateShelf(@RequestBody ShelfVo shelfVo){
        int i = shelfService.updateShelf(shelfVo);
        return i>0?Result.ok("修改成功"):Result.ok("修改失败");
    }


    //删除货架
    @ApiOperation(value = "删除货架")
    @PostMapping("shelf/delete/{shelfId}")
    public Result deleteShelf(@PathVariable  Integer shelfId){

        int i = shelfService.deleteShelf(shelfId);
        return i>0?Result.ok("删除成功"):Result.ok("删除失败");
    }

    //查询货架
    @ApiOperation(value = "查询货架")
    @PostMapping("shelf/search")
    public Result searchShelf(@RequestBody ShelfVo shelfVo){
        Page page = shelfService.searchShelf(shelfVo);

        return Result.ok(page);
    }


    //查询所有货架名称
    @ApiOperation(value = "查询所有货架名称")
    @PostMapping("shelf/searchName")
    public Result searchShelfName(){
        return Result.ok(shelfService.searchShelfName());
    }



}
